$(document).ready(function() {
            
    if(method=='home' || method=='initialze' || method=='browse_car_details' || method=='browse_fleet')
    {
        // Custom combox
        $('.dropdownized').dropdownized(); 
    }

    // Picup location disables Return location
    $('#pickup_loc_id').live('change', function(){

        var sID = $('#pickup_loc_id').val(); 
        $('#pickup_loc_id2').val(sID).trigger('change');

        var $dd = $('#return_loc_id');
        if ($dd.length > 0) { // make sure we found the select we were looking for

            // save the selected value
            var selectedVal = $dd.val();

            // get the options and loop through them
            var $options = $('option', $dd);
            var arrVals = [];
            $options.each(function(){

                if($(this).val()==sID||$.inArray($(this).val(), returLocations)!=-1){

                    $(this).removeAttr('disabled');

                }else{
                    $(this).attr('disabled','disabled');
                //console.log($(this).text())
                //console.log($(this).val())
                }
            });
        }
        $('#return_loc_id').val(sID).trigger('change');

        var $dd = $('#return_loc_id2');
        if ($dd.length > 0) { // make sure we found the select we were looking for

            // save the selected value
            var selectedVal = $dd.val();

            // get the options and loop through them
            var $options = $('option', $dd);
            var arrVals = [];
            $options.each(function(){

                if($(this).val()==sID||$.inArray($(this).val(), returLocations)!=-1){

                    $(this).removeAttr('disabled');

                }else{
                    $(this).attr('disabled','disabled');
                //console.log($(this).text())
                //console.log($(this).val())
                }
            });
        }
        $('#return_loc_id2').val(sID).trigger('change');


    })

    // Picup location disables Return location
    $('#pickup_loc_id2').live('change', function(){

        var sID = $('#pickup_loc_id2').val(); 
        $('#pickup_loc_id').val(sID);
        var $dd = $('#return_loc_id2');
        if ($dd.length > 0) { // make sure we found the select we were looking for

            // save the selected value
            var selectedVal = $dd.val();

            // get the options and loop through them
            var $options = $('option', $dd);
            var arrVals = [];
            $options.each(function(){

                if($(this).val()==sID||$.inArray($(this).val(), returLocations)!=-1){

                    $(this).removeAttr('disabled');

                }else{
                    $(this).attr('disabled','disabled');
                //console.log($(this).text())
                //console.log($(this).val())
                }
            });
        }
        $('#return_loc_id2').val(sID).trigger('change');

        var $dd = $('#return_loc_id');
        if ($dd.length > 0) { // make sure we found the select we were looking for

            // save the selected value
            var selectedVal = $dd.val();

            // get the options and loop through them
            var $options = $('option', $dd);
            var arrVals = [];
            $options.each(function(){

                if($(this).val()==sID||$.inArray($(this).val(), returLocations)!=-1){

                    $(this).removeAttr('disabled');

                }else{
                    $(this).attr('disabled','disabled');
                //console.log($(this).text())
                //console.log($(this).val())
                }
            });
        }
        $('#return_loc_id').val(sID);


    })

    $('#pickup_loc_id').val(1).trigger('change');
    $('#pickup_loc_id2').val(1);

    $('#return_loc_id').live('change', function(){
        var sID = $('#return_loc_id').val(); 
        $('#return_loc_id2').val(sID).trigger('change');
    })

    $('#return_loc_id2').live('change', function(){
        var sID = $('#return_loc_id2').val(); 
        $('#return_loc_id').val(sID);
    })

    $('#fullfrom').live('change',function(){
        $('#fullfrom2').val($(this).val()).trigger('change');
        return false;
    })

    $('#fullfrom2').live('change',function(){
        $('#fullfrom').val($(this).val());
        return false;
    })

    $('#fullto').live('change',function(){
        $('#fullto2').val($(this).val()).trigger('change');
        return false;
    })

    $('#fullto2').live('change',function(){
        $('#fullto').val($(this).val());
        return false;
    })

    // Initialize datepickers
    if(method!='checkout'&&method!='checkout_show_order'){
        init_dates();
        $('.dropdownized').dropdownized(); 
    }

    // Search car
    $('#changeDetasilsButton').live('click',function(){

        $('#changeDetasilsBox').hide();
        $('#serchModule').show();
        // Custom combox
        $('.dropdownized').dropdownized();
        return false;

    })
    //log = console.log;

    $('#go_to_checkout').live('click',function(){
        if( method=='browse_car_details'){
            $('input.form-button').trigger('click');
            return false;
        }

        $('#redirect_checkout').val(1);
        $('input.form-button').trigger('click');
        return false;
    })
        
    $('#redirect_checkout').val(0);

    //log(method)

    if(method=='car_details' || method=='browse_car_details' || method=='get_car_quote')
    {
        // Lightbox
        $('a[rel=lightbox]').lightBox({
            overlayBgColor: '#000',
            overlayOpacity: 0.6,
            imageLoading: base_url+'assets/img/lightbox/loading.gif',
            imageBtnClose: base_url+'assets/img/lightbox/close.gif',
            imageBtnPrev: base_url+'assets/img/lightbox/prev.gif',
            imageBtnNext: base_url+'assets/img/lightbox/next.gif',
            imageBlank : base_url+'assets/img/lightbox/blank.gif',
            containerResizeSpeed: 350,
            txtImage: 'Image',
            txtOf: 'of'
        });
        init_dates2();

    }

    $('#set_extras').live('click',function(){

        //return false;
        })

	$('.search-list .car-box .details p').trunk8({ lines: 2});
	$('.car-box h4').trunk8({ lines: 2});
});

$(window).load(function() {
	$('.search-list .car-box .details p').trunk8({ lines: 2});
	$('.car-box h4').trunk8({ lines: 2});
});